package statics;

import batch.common.db.*;
import batch.common.db.ExecQuery;
import batch.common.report.*;
import batch.common.util.*;

import java.util.Vector;
import java.util.Properties;
import java.sql.*;
import org.apache.log4j.Logger;
import java.util.Calendar;

 

public class Top5ModelMonth {

    // �α����� ����
	String startTime = null;
	String endTime = null;
	String defaultTime = null;
 
	String startDate = null;
	String endDate = null;
	boolean bResult = false;

    public Top5ModelMonth(String strDate) {

        Calendar now = Calendar.getInstance();
		now.add(Calendar.MONTH , -1);
        if(strDate.equals("") || strDate == null) strDate = new java.text.SimpleDateFormat("yyyyMM").format(now.getTime());

		//Last Day
        int year  = Integer.parseInt(strDate.substring(0,4)); 
		int month = Integer.parseInt(strDate.substring(4,6));     	
		now.set(year, month - 1, 1);
		
    	this.defaultTime = strDate;
        this.startDate = strDate + "01";
        this.endDate = strDate + String.valueOf(now.getActualMaximum(Calendar.DATE));
        
    }

    private void exec() {
    	boolean bRe = false;
    	LogWriter.setFistStart("Top5ModelMonth.class", "Top5ModelMonth");
		LogWriter.setStart();
		
		startTime = Utils.getLocalDateTime();
		bRe = select_insert();
		endTime = Utils.getLocalDateTime();
		
		LogWriter.setEnd();
		LogWriter.setStatStart();
		LogWriter.setStatTime(startTime, endTime);
		LogWriter.setStatEnd();
		if(bRe){
			LogWriter.setLog("SUCCESS");
		}else{
			LogWriter.setLog("FAIL");
		}
		
    }


    private boolean select_insert() {
        Connection conn = null;

        String strQuery = null;
        Vector vcTable = null;

        int nSiteCount = 0;

        String countryName = null;

        try {
            conn = ConnectionManager.getConnection();

            ExecQuery eq = new ExecQuery();

            // renewal start

            LogWriter.setLog("******************* G_HIS_TOP5_MONTH  Renewal START *********************************");            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### GBR ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='gbr'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### GBR ### Insert END");
            

            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### GER ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='ger'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### GER ### Insert END");            


            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ESP ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='esp'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ESP ### Insert END");            
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### RUS ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='rus'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### RUS ### Insert END");            
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ITA ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='ita'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ITA ### Insert END");                        
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ZAF ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='zaf'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### ZAF ### Insert END");                                    
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### BEL ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='bel'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### BEL ### Insert END");                                    
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### NLD ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='nld'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### NLD ### Insert END");                                                
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### PRT ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='prt'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### PRT ### Insert END");                                                
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### NRD ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='nrd'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### NRD ### Insert END"); 
            
            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### POL ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='pol'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### POL ### Insert END");                                                                                                           

            
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### TUR ### Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='tur'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);
            LogWriter.setLog("G_HIS_TOP5_MONTH Renewal ### TUR ### Insert END");            
            

			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MEA ###  Insert START");
         	strQuery = 	" INSERT INTO G_HIS_TOP5_MONTH																						 			\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='mea'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
         	eq.exec(conn, strQuery);															
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MEA ###  Insert END");            
            
            
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### BRA ###  Insert START");
			            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='bra'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### BRA ###  Insert END");

         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### CHL ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='chl'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### CHL ###  Insert END");         	

         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MEX ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='mex'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MEX ###  Insert END");         	
         	
            
         	LogWriter.setLog("******************* G_HIS_TOP5_MONTH 2008 NEW OPEN SITE START *********************************");         	

         		
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### COL ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='col'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### COL ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### VEN ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='ven'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### VEN ###  Insert END");         	
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### ARG ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='arg'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### ARG ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PAK ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='pak'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PAK ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### NGA ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='nga'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### NGA ###  Insert END");
         	

			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### DZA ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='dza'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### DZA ###  Insert END");      
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### CZE ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='cze'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### CZE ###  Insert END");    
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### ROU ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='rou'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### ROU ###  Insert END"); 
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### HRV ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='hrv'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### HRV ###  Insert END"); 
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SVK ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='svk'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SVK ###  Insert END"); 
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SVN ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='svn'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SVN ###  Insert END"); 
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### GRC ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='grc'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### GRC ###  Insert END");
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### BGR ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='bgr'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### BGR ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SRB ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='srb'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SRB ###  Insert END");
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### IRN ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='irn'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### IRN ###  Insert END");
         	

			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### EGY ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='egy'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### EGY ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MAR ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='mar'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### MAR ###  Insert END");
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SAU ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='sau'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### SAU ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PER ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='per'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PER ###  Insert END");
         	
         	
			LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PCC ###  Insert START");
            strQuery =  "INSERT INTO G_HIS_TOP5_MONTH 																																																																											\n"+
						" select site as reg_country, created, hp_model, cnt, rank1, rank2, sn, language as lang_cd																																																							\n"+		
						"    from (select created, site,language, hp_model, cnt,                                                                                                                                     \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                                             \n"+
						"                 rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                                             \n"+
						"                 sn                                                                                                                                                                \n"+
						"          from (select '"+defaultTime+"' created, site,language, hp_model, decode(his_cd,'1002001',decode(site,'rus',2,'uan',2,1),'1002006',2,'1002005',3,0) sn, count(*) cnt, grouping(hp_model) m  \n"+
						"                from (select created, site,language, hp_model, his_cd                                                                                                                       \n"+
						"                      from (select m.created created, m.reg_country site,decode(m.language,'',GET_LANG_NULL(m.reg_country),m.language) as language, z.hp_model, z.his_cd,                                                                                    \n"+
						"                                   row_number() over (partition by m.reg_country, z.hp_model, m.user_no order by z.his_cd desc) rnum                                               \n"+
						"                            from g_mb_buy_history z, g_mb_member m                                                                                                                 \n"+
						"                            where z.user_no=m.user_no                                                                                                                              \n"+
						"                                  and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                                     \n"+
						" 																 and m.reg_country='pcc'                                                                                                                          \n"+
						"                                  and z.his_cd in ('1002001','1002005', '1002006')                                                                                                 \n"+
						" 								 								 and z.hp_model is not null                                                                                                                       \n"+
						"                                  and z.hp_model <> 'WAP_TEMP'                                                                                                                     \n"+
						"                                  and z.hp_model <> 'SIM_TEMP')                                                                                                                    \n"+
						"                      where rnum=1)                                                                                                                                                \n"+
						"                group by site,language, rollup(hp_model, his_cd))                                                                                                                           \n"+
						"          where m=0)                                                                                                                                                               \n"+
						"    where rank2 <= 5                                                                                                                                                               \n";
            eq.exec(conn, strQuery);															
         	LogWriter.setLog("G_HIS_TOP5_MONTH Renewal  ### PCC ###  Insert END");
         	
         	
         	LogWriter.setLog("******************* G_HIS_TOP5_MONTH 2008 NEW OPEN SITE END *********************************");
         	
         	
         	
            LogWriter.setLog("******************* G_HIS_TOP5_MONTH Non Renewal START *********************************");         	

			/*LogWriter.setLog("G_HIS_TOP5_MONTH Non Renewal  ### EUR ###  Insert START");
         	strQuery = 	" INSERT INTO G_HIS_TOP5_MONTH																						 			\n"+
						" select site, created, hp_model, cnt, rank1, rank2, sn , 'ENG'	as lang_cd																																																			\n"+
						" from (select created, site, hp_model, cnt,                                                                                                                  \n"+
						"              rank() over (partition by created, site, sn order by cnt desc) rank1,                                                                          \n"+
						"             rank() over (partition by created, site, sn order by cnt desc) rank2,                                                                           \n"+
						"              sn                                                                                                                                             \n"+
						"       from (select '"+defaultTime+"' created, m.reg_country site, decode(c.point_cd,'00101',2,'00106',3,0) sn, m.hp_model, count(*) cnt, grouping(m.hp_model) m      \n"+
						"             from g_eur_point_history c, g_mb_member m                                                                                                       \n"+
						"             where c.user_id=m.id                                                                                                                            \n"+
						"                   and m.created>=to_date('"+startDate+"','yyyymmdd') and m.created<to_date('"+endDate+"','yyyymmdd')+1                                              \n"+
						"                   and point_cd in ('00101','00106')                                                                                                         \n"+
						"                   and m.reg_country='eur'                                                                                                                   \n"+
						"                   and m.hp_model is not null                                                                                                                \n"+
						"                   and m.hp_model <> 'WAP_TEMP'                                                                                                              \n"+
						"                   and m.hp_model <> 'SIM_TEMP'                                                                                                              \n"+
						"             group by m.reg_country, rollup(m.hp_model, c.point_cd))                                                                                         \n"+
						"       where m=0)                                                                                                                                            \n"+
						" where rank2 <= 5                                                                                                                                            \n";
			eq.exec(conn, strQuery);															
			LogWriter.setLog("G_HIS_TOP5_MONTH Non Renewal  ### EUR ###  Insert END");*/
           
			conn.commit();
            bResult = true;            	
        } catch (Exception e) {
        	if (conn != null) {
                try {
                    conn.rollback();
                } catch (Exception se) {}
            }
            e.printStackTrace();
            LogWriter.setErr(e.toString());
            Logger.getLogger("nohup").error(strQuery);
            bResult = false;
            batch.common.report.ReportError.byEmail("Error of Top5ModelMonth Error! (" + defaultTime + ") !!", e.toString());
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                    conn = null;
                } catch (Exception se) {}
            }
        }
        return bResult;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        new Top5ModelMonth(args[0]).exec();
    }

}